/*
 * User: rant
 * Date: Jul 30, 2007
 *
 * 
 */
package laMalinche;

import laMalinche.rete.nodes.tailing.AccessReporter;
import laMalinche.rete.nodes.TrigerConditionNode;
import laMalinche.constraint.ConstraintManager;

import java.util.Map;
import java.util.HashMap;

import com.google.inject.Inject;

/**
 *
 */
public class LaMaContext {
    private ConstraintManager constraintManager;
    private AccessReporter accessReporter;
    private static LaMaContext instance;
    private Map<String, TrigerConditionNode> trigerConditionMap = new HashMap<String, TrigerConditionNode>();

    public AccessReporter getAccessReporter() {
        return accessReporter;
    }

    private LaMaContext() {
        DevMode.getInstance().getInjector().injectMembers(this);

    }

    public static LaMaContext getInstance() {
        if (instance == null) {
            instance = new LaMaContext();
        }
        return instance;

    }

    public void setAccessReporter(final AccessReporter accessReporter) {
        this.accessReporter = accessReporter;
    }

    @Inject
    public ConstraintManager getConstraintManager() {
        return constraintManager;
    }

   @Inject 
    public void setConstraintManager(final ConstraintManager constraintManager) {
        this.constraintManager = constraintManager;
    }

    public TrigerConditionNode getTrigerCondition(String trigerName) {
        if (!trigerConditionMap.containsKey(trigerName)) {
            trigerConditionMap.put(trigerName, new TrigerConditionNode());
        }
        return trigerConditionMap.get(trigerName);
    }

    public void detach() {
        trigerConditionMap = new HashMap<String, TrigerConditionNode>();
    }
}